package net.oschina.git.haxteam.zrank.jdbc;

import com.zaxxer.hikari.HikariDataSource;

import net.oschina.git.haxteam.zrank.main.Main;

public class ConnectionManager  {

	private static ConnectionManager  connectionManager = null;
	private static HikariDataSource hikariDataSource = null;

	private ConnectionManager (){
		System.out.println("[等级&成就]数据库连接池开始配置!");
		hikariDataSource = new HikariDataSource();
		hikariDataSource.setJdbcUrl(Main.config.getString("配置数据库.url") + "?allowMuiltiQueries=true&autoReconnect=true&useUnicode=true&characterEncoding=utf8");
		hikariDataSource.setUsername(Main.config.getString("配置数据库.数据库用户名"));
		hikariDataSource.setPassword(Main.config.getString("配置数据库.数据库密码"));
		hikariDataSource.setConnectionTimeout(1000);
		hikariDataSource.setIdleTimeout(600000);
		hikariDataSource.setMaxLifetime(1800000);
		hikariDataSource.setMaximumPoolSize(100);
		hikariDataSource.setMinimumIdle(10);
		hikariDataSource.setPoolName("数据库连接池-1");
		System.out.println("[等级&成就]数据库连接池配置完成!");
	}

	public static ConnectionManager  getInstance(){
		if (connectionManager == null){
			connectionManager = new ConnectionManager ();
		}
		return connectionManager;
	}

	public HikariDataSource getHikariDataSource() {
		return hikariDataSource;

	}

}
